/**
 * AspectSense project
 *
 * Middleware for annotation-based, context-aware and adaptive services for
 * mobile and ubiquitous computing
 *
 * This project is an open-source effort, started at the University of Cyprus
 * [http://www.ucy.ac.cy].
 *
 * More information about the project is available at
 * [http://code.google.com/p/aspectsense]
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package org.aspectsense.example_apps.sorted_helloworld;

import org.aspectsense.annotations.Component;
import org.aspectsense.annotations.RequiredService;
import org.aspectsense.annotations.Service;
import org.aspectsense.annotations.ServiceUtility;
import org.aspectsense.framework.DefaultComponent;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

/**
 * <p/>
 * Date: Sep 10, 2007<br/>
 * Time: 6:22:59 PM
 * </p>
 *
 * @author Nearchos Paspallis [nearchos@cs.ucy.ac.cy]
 */
@Component(
        displayID = "HelloWorldImpl"
)
@Service(
        serviceType = HelloWorldService.class
)
@ServiceUtility(
        targetServiceType = HelloWorldService.class,
        utilityFunction =
                "0.4 * utility[org.aspectsense.example_apps.sorted_helloworld.EchoService] + "
              + "0.6 * utility[org.aspectsense.example_apps.sorted_helloworld.SortingService]"
)
public class HelloWorldImpl
        extends DefaultComponent
        implements HelloWorldService // the empty service is implemented as a dummy end-user service
{
    @RequiredService(
            variationPointID = "echoServiceID"
    )
    private EchoService echoService = null;

    @RequiredService(
            variationPointID = "sortingServiceID"
    )
    private SortingService sortingService = null;

    public void activate()
    {
        super.activate();

        Set<String> set = new HashSet<String>();

        String message = "Hello World ! This is a simple AspectSense adaptation";
        StringTokenizer stringTokenizer = new StringTokenizer(message);
        while(stringTokenizer.hasMoreTokens())
        {
            set.add(stringTokenizer.nextToken());
        }

        List list = sortingService.sort(set);
        echoService.echo(list);
    }
}